<?php

class validUserValidator extends sfValidator
{

  public function initialize($context, $parameters = null)
  {
    // initialize parent
    parent::initialize($context);

    // set defaults
    $this->setParameter('user_error', 'Compte inexistant');

    $this->getParameterHolder()->add($parameters);

    return true;
  }

  public function execute(&$value, &$error)
  {
    $email_param = $this->getParameter('email');
    $email = $this->getContext()->getRequest()->getParameter($email_param);

    $c = new Criteria();
    $c->add(GuardUserPeer::EMAIL, $email);
    $user = GuardUserPeer::doSelectOne($c);

    // user exist with this email ?
    if ($user)
    {
      return true;
    }

    $error = $this->getParameter('user_error');
    return false;

  }

}
